<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con">
            <span>新建</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">


        <div class="block-generic">


                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="edittits"><span>基本信息</span></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>部门名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>上级部门</label>
                            <div class="layui-input-block">
                                <div id="pid"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>部门类型</label>
                        <div class="layui-input-block radio-block" id="typeDiv">
                            <input type="radio" name="type" lay-filter="type" checked value="1" title="部门">
                            <input type="radio" name="type" lay-filter="type" value="2" title="单位">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">部门负责人</label>
                            <div class="layui-input-block">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=fuer&type=user&single=1', '770px', '490px');"></div>
                                    <div class="tanxiannei" id="fuer"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=fuer&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item height_auto">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label label_textarea">备注</label>
                            <div class="layui-input-block">
                                <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block radio-block">
                            <input type="radio" name="status" lay-filter="status" checked value="1" title="正常">
                            <input type="radio" name="status" lay-filter="status" value="0" title="停用">
                        </div>
                    </div>
                </div>
            </div>
    </div>
</form>
<script>

    $("#commentForm").validate({
        rules: {
            name: {required: true},
        },
        messages:{
            name: {required: "请输入"},
        }
    });
    render_input_attr();
    layui.use(['laytp', 'form', 'table'], function() {
        var form = layui.form, layer = layui.layer, table = layui.table;

        facade.ajax({type: 'get', url: ask_dept_add}).done(function(res){
            if (res.code === 2000) {

                var pidXmObj = xmselect_dan('pid', res.data.deptArr, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#pid").find('xm-select').removeClass('error');
                    }else{
                        $("#pid").find('xm-select').addClass('error');
                    }
                })

                render_from();
            }
        });

        form.on('submit(add)', function(data){

            data.field.fuer = tan_tags_getvalue("#fuer", 'user');

            var validRes = $("#commentForm").valid();
            if(!data.field.pid){
                $("#pid").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#pid").find('xm-select').removeClass('error');
            }
            if(!validRes){return false;}

            facade.ajax({url: ask_dept_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    parent.searchTableFunc(form, table);
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



</script>
</body>
</html>
